package club.easin.utils;

import org.springframework.beans.BeanUtils;

import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Map;

public class Tdata {
    private String mName;//方法名
    private String daoName;//类名
    private Object[] Value; //参数

    public String getmName() {
        return mName;
    }

    public void setmName(String mName) {
        this.mName = mName;
    }

    public String getDaoName() {
        return daoName;
    }

    public void setDaoName(String daoName) {
        this.daoName = daoName;
    }

    public Object[] getValue() {
        return Value;
    }

    public void setValue(Object... value) {
        if (value.length > 0) {
            this.Value = new Object[value.length];
            for (int i = 0; i < value.length; i++) {
                Value[i] = colneValue(value[i]);
            }
        }
    }

    public Object colneValue(Object value) {

        Object tResult = null;
        try {
            if (value == null) {
                tResult = value;
            } else if (value instanceof String) {
                tResult = value;
            } else if (value instanceof Integer) {
                tResult = value;
            } else if (value instanceof Double) {
                tResult = value;
            } else if (value instanceof ArrayList) {
                ArrayList<Object> tlist = (ArrayList) value;
                ArrayList<Object> newList = new ArrayList<Object>();
                for (int i = 0; i > tlist.size(); i++) {
                    newList.add(colneValue(tlist.get(i)));
                }
                tResult=newList;
            }else if(value instanceof Map){
                tResult=value;
            }else if(value instanceof Boolean){
                tResult=value;
            }else if(value instanceof Long){
                tResult=value;
            }
            else{
                Class<?> vcalss=value.getClass();
                for(Method m:vcalss.getMethods()){
                    if("clone".equalsIgnoreCase(m.getName())){
                        tResult=m.invoke(value);
                        break;
                    }
                }
                if(tResult==null){
                    tResult=value.getClass().getInterfaces();
                    BeanUtils.copyProperties(tResult,value);
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
            return value;
        }

        return tResult;


    }
}
